import { _decorator, Component, Node, Button, EventHandler, debug, instantiate, Prefab } from 'cc';
import { CommonUI } from "../Scripts/[框架]/通用UI/CommonUI";
import { UIManager } from "../Scripts/[框架]/通用UI/UIManager";
import { GYComponent } from '../Scripts/[框架]/Core/组件基类/GYComponent';
import TaskWeb from '../Scripts/[业务]/广告任务/Controller/TaskWeb';
import TaskResMgr from '../Scripts/[业务]/广告任务/Model/TaskResMgr';

const { ccclass, property } = _decorator;

@ccclass('TestScene')
export default class TestScene extends GYComponent {
    @property(Node)
    private btnTask: Node = null;

    async start() {

    }

    protected async onEnable(): Promise<void> {
        const uiManager = UIManager.getInstance();
        await uiManager.init();
        await TaskResMgr.init();
        this.btnTask.on(Node.EventType.TOUCH_END, this.showTask, this);
    }

    private async showTask() {

        CommonUI.showLoading({ title: "获取任务..." });
        let res = await TaskWeb.getTaskConfig();
        CommonUI.hideLoading();
        let taskView = instantiate(TaskResMgr.taskViewPrefab);
        UIManager.instance.addChildTo(taskView as any, "normal");
    }

    private testShowInput() {
        // CommonUI.showInput({
        //     title: "绑定测试",
        //     showCancel: true,
        //     cancelText: "取消哈",
        //     confirmText: "确定哈",
        //     success: (res) => {
        //         if (res.confirm) {
        //             CommonUI.showModal({
        //                 showCancel: false,
        //                 content: `点击了确定\r\n${res.value1}\r\n${res.value2}`
        //             })
        //         }
        //         else {
        //             CommonUI.showModal({
        //                 showCancel: false,
        //                 content: "点击了取消"
        //             })
        //         }
        //     }
        // })
    }

    private testShowModal() {
        // CommonUI.showLoading({ title: "获取任务..." });
        CommonUI.showToast("哈哈哈 哈哈哈 所发生的的方式是")
        // CommonUI.showModal({
        //     showCancel: true,
        //     title: "测试",
        //     confirmText: "确定1",
        //     cancelText: "取消1",
        //     content: "这是一个通用showModal弹窗",
        //     success: (res) => {
        //         if (res.confirm) {
        //             CommonUI.showModal({
        //                 showCancel: false,
        //                 content: "点击了确定"
        //             })
        //         } else {
        //             CommonUI.showModal({
        //                 showCancel: false,
        //                 content: "点击了取消"
        //             })
        //         }
        //     }
        // });
    }
}